package poo.mvc;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Vista {

	private JTextField counterValue;
	private JButton increment, decrement, azzera;

	public Vista() {
		// finestra
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(300, 300);
		f.setLocation(200, 200);
		f.setVisible(true);
		f.setTitle("CONTATORE");

		// pannello
		JPanel p = new JPanel();
		p.setLayout(new FlowLayout());
		counterValue = new JTextField(20);
		p.add(counterValue, BorderLayout.NORTH);
		// aggiunta pannello alla finestra
		f.add(p);

		// bottoni
		increment = new JButton("Incrementa");
		decrement = new JButton("Decrementa");
		azzera = new JButton("Azzera");
		p.add(increment, BorderLayout.WEST);
		p.add(decrement, BorderLayout.EAST);
		p.add(azzera, BorderLayout.CENTER);
		
	}// Vista

	public void update(int n) {
		counterValue.setText(n + "");
	}// update
	
	

	public void setController(ActionListener l) {
		increment.addActionListener(l);
		decrement.addActionListener(l);
		azzera.addActionListener(l);
	
	}

}
